package com.wxq.product.config;


import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Jim
 * @date 9:27 下午 2022/4/9
 * @description 线程池配置
 * @email:huwmz04153277@126.com
 */
@Configuration
@EnableConfigurationProperties(ThreadPoolProperties.class)
public class ThreadPoolConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolProperties threadPool){
        return new ThreadPoolExecutor(
        threadPool.getCoreSize(),
        threadPool.getMaxSize(),
        threadPool.getKeepAliveTime(),
                TimeUnit.SECONDS,
        new LinkedBlockingDeque<>(threadPool.getQueueSize()),
                Executors.defaultThreadFactory(),
        new ThreadPoolExecutor.AbortPolicy());
    }
}
